package com.noname.lib_base_java.net.interceptor;

import com.noname.lib_base_java.util.L;
import com.noname.lib_base_java.util.SharedPrefUtil;

import java.io.IOException;

import okhttp3.HttpUrl;
import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;

/**
 * Author: Lmoumou
 * Date: 2018-10-15 15:01
 * 文件名: NetInterceptor
 * 描述:
 */
public class NetInterceptor implements Interceptor {
    @Override
    public Response intercept(Chain chain) throws IOException {
        Request requestOld = chain.request();
        //添加公共参数
        HttpUrl httpUrl = requestOld.url().newBuilder()
//                .addQueryParameter("userId", AppHelper.UserHelp.getAuthUserId())
                .build();

        L.e("NetInterceptor","token->"+SharedPrefUtil.open(SharedPrefUtil.NAME).getString("token"));
        //添加公共请求头
        Request requestNew = requestOld.newBuilder()
                .header("token", SharedPrefUtil.open(SharedPrefUtil.NAME).getString("token"))
                .url(httpUrl)
                .build();
        return chain.proceed(requestNew);
    }
}
